package cc.magicjson.synthesis.context;

import cc.magicjson.synthesis.model.Order;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * 折扣上下文类，用于在责任链各节点间传递信息
 */
@Getter
@Setter
@ToString
public class DiscountContext {
    private final Order order;  // 订单信息
    private final Map<String, Object> attributes = new HashMap<>(); // 存储处理过程中的各种属性
    private final Map<String, BigDecimal> discountDetails = new HashMap<>(); // 各种折扣的详细信息

    public DiscountContext(Order order) {
        this.order = order;
    }


    // 添加属性
    public void setAttribute(String key, Object value) {
        attributes.put(key, value);
    }

    // 获取属性
    @SuppressWarnings("unchecked")
    public <T> T getAttribute(String key) {
        return (T) attributes.get(key);
    }

    // 添加折扣明细
    public void addDiscountDetail(String discountType, BigDecimal amount) {
        discountDetails.put(discountType, amount);
    }

}
